/*静态配置库操作
Created on 2020年05月10日
@author: zxyong 13738196011
 */

package com.zxy.db_Self;

import com.zxy.common.DbConfigSelf;
import java.sql.Connection;
import java.sql.SQLException;

public class DBManager_Self
{
	private static PooledConnection_Self	conn;
	public static ConnectionPool_Self		connectionPool;
	public static DBManager_Self			inst;

	public void close()
	{
		try
		{
			connectionPool.closeConnectionPool();
		}
		catch(SQLException localSQLException)
		{
		}
	}

	public DBManager_Self()
	{
		if(inst != null)
			return;
		if(DbConfigSelf.url == null)
			DbConfigSelf.GetDbConfigSelfNew();
		String connStr = DbConfigSelf.url;
		connectionPool = new ConnectionPool_Self(DbConfigSelf.driverClassName,connStr,DbConfigSelf.username,DbConfigSelf.password);
		try
		{
			connectionPool.createPool();
			inst = this;
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	public static PooledConnection_Self getConnection()
	{
		if(inst == null)
			new DBManager_Self();
		try
		{
			conn = connectionPool.getConnection();
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		return conn;
	}

	public static void returnConnection(Connection conn)
	{
		connectionPool.returnConnection(conn);
	}

	public static void closeConnectionPoolTimeOut()
	{
		try
		{
			connectionPool.closeConnectionPoolTimeOut();
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
	}
}